#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int arr1[2004];
int arr2[2004];
int main() {
    int a, b;
    scanf("%d%d", &a, &b);
    for (int i = 0; i < a; i++) {
        scanf("%d", &arr1[i]);
    }
    for (int i = 0; i < b; i++) {
        scanf("%d", &arr2[i]);
    }
    for (int i = 0; i < a; i++) {
        for (int j = 0; j < b; j++) {
            if (j == 0 && arr1[i] <= arr2[j]) {
                for (int r = b - 1; r > j - 1; r--)
                    arr2[r + 1] = arr2[r];
                arr2[j] = arr1[i];
                b++;
                break;
            }
            else if (arr1[i] >= arr2[j] && arr1[i] <= arr2[j + 1]) {
                for (int r = b - 1; r > j; r--)
                    arr2[r + 1] = arr2[r];
                arr2[j + 1] = arr1[i];
                b++;
                break;
            }
            else if (arr1[i] >= arr2[b - 1]) {
                arr2[b] = arr1[i];
                b++;
                break;
            }
        }
    }
    for (int i = 0; i < b; i++)
        printf("%d ", arr2[i]);
    return 0;
}